package com.cysd.ewmxns.ui.activity

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.cszy.ewmxns.base.BaseVMActivity
import com.cszy.ewmxns.ext.launch
import com.cszy.ewmxns.ext.toast

import com.cysd.ewmxns.utils.SpUtils
import com.cysd.ewmxns.utils.generateQRCode
import com.cysd.ewmxns.viewmodel.MainViewModel
import com.hlyj.http.ad.NewGroMoreFeedAdManager
import com.hlyj.http.base.tool.lib_hlyj_base.utils.BaseAppConstans
import com.hnyyac.ad.mds.IAdView
import com.hnyyac.ad.mds.IAdViewListener
import com.hnyyac.ad.mds.manager.AdManager
import com.hnyyac.ad.mds.manager.AdManager.AdLoadListener
import com.hnyyac.ad.mds.utils.BaseAdConstants
import qrrspeeelild.rqrc0ode.andro0ild.databinding.ActivityCreatQrCodeBinding


class CreatQrCodeActivity : BaseVMActivity<MainViewModel, ActivityCreatQrCodeBinding>(),IAdViewListener {
    private var newGromoreFeedAd : NewGroMoreFeedAdManager? =null
    var app_process: String? = "0" //整个应用流程
    override fun initView(savedInstanceState: Bundle?) {
        mBinding.headTitle.headCenterTitle.text = "生成二维码"
        app_process = SpUtils.getInstance().getString(BaseAppConstans.APP_PROCESS)
    }

    override fun initData() {
        AdManager.loadChapin(
            this,
            2,
            this,
            object : AdLoadListener {
                override fun onAdLoadFailed(ad: IAdView?) {
                    newGromoreFeedAd = NewGroMoreFeedAdManager(this@CreatQrCodeActivity, BaseAdConstants.FEEDAD_Id, mBinding?.fragmentContainer,22)
                    newGromoreFeedAd?.loadAd()
                }
            })
    }

    override fun initListener() {
        mBinding.headTitle.headBack.setOnClickListener {
            finish()
        }
       mBinding.main.setOnClickListener {
            hideKeyboard(mBinding.main)
       }
        mBinding.btnCreat.setOnClickListener {


            val content = mBinding.evContent.text.toString()
            if (content.isEmpty()) {
                toast("请输入内容")

            }else{
                if (app_process == "0"){//黑名单界面
                    var bundle=Bundle()
                    bundle.putString("content",content)
                    launch(bundle,CreatQrCodeResultActivity::class.java)
                    finish()
                }else{
                    var bundle=Bundle()
                    bundle.putString("content",content)
                    launch(bundle,CreatQrcodeProGressActivity::class.java)
                    finish()
                }

            }
        }
    }

    override fun onTrigger(adView: IAdView) {

    }

    override fun onAdShow(adView: IAdView) {

    }

    override fun onAdClick(adView: IAdView) {

    }

    override fun onAdClose(adView: IAdView) {
        newGromoreFeedAd = NewGroMoreFeedAdManager(this@CreatQrCodeActivity, BaseAdConstants.FEEDAD_Id, mBinding?.fragmentContainer,22)
        newGromoreFeedAd?.loadAd()
    }

    override fun onError(msg: String) {

    }

    override fun onLoadError(adView: IAdView) {

    }

    override fun onSuccess(adView: IAdView) {

    }

    override fun onLoad(adView: IAdView) {

    }

    override fun onSkipped() {

    }

    override fun onNoAd() {

    }

    override fun onTimeOut() {

    }
    fun hideKeyboard(view: View) {
        val inputMethodManager = view.context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
        inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
    }

}